package com.sky.controller.article;

import com.sky.dto.ArticleCommentDTO;
import com.sky.dto.ArticleSubmitDTO;
import com.sky.dto.ArticleTagsDTO;
import com.sky.result.Result;
import com.sky.service.ArticleService;
import com.sky.vo.ArticleCommentsVO;
import com.sky.vo.ArticleInfoVO;
import com.sky.vo.ArticleTreeListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 贾晓晨
 * @version 1.0
 */
@RestController
@RequestMapping("/article")
@Slf4j
@Api(tags = "文章接口")
public class ArticleController {
    @Autowired
    ArticleService articleService;

    @GetMapping
    @ApiOperation("获取文章详情")
    // 通过id获取文章详情内容
    public Result<ArticleInfoVO> getArticleInfo(@RequestParam String id) {
        ArticleInfoVO articleInfoVO = articleService.getArticleDetail(id);
        return Result.success(articleInfoVO);
    }

    @PostMapping
    @ApiOperation("提交文章")
    public Result pushArticle(@RequestBody ArticleSubmitDTO articleSubmitDTO) {
        // 保存文章信息
        articleService.saveArticle(articleSubmitDTO);
        // 保存tag信息
        articleService.saveTag(articleSubmitDTO.getTags());
        return Result.success("文章发送成功");
    }

    @PostMapping("/pushComment")
    @ResponseBody
    @ApiOperation("评论接口")
    public Result pushArticleComment(@RequestBody ArticleCommentDTO articleCommentDTO) {
        articleService.sendFirstComment(articleCommentDTO);
        return Result.success("发送评论成功");
    }

    @GetMapping("/getComments/{articleUserId}")
    @ApiOperation("获取评论接口")
    public Result<ArticleCommentsVO> getComments(@PathVariable String articleUserId) {
        ArticleCommentsVO act = articleService.getCommentsByArticleUserId(articleUserId);
        return Result.success(act);
    }

    // 获取文章的节点排列信息
    @GetMapping("/getTreeList")
    @ApiOperation("获取文章的节点排列信息")
    public Result<List<ArticleTreeListVO>> getTreeList() {
        List<ArticleTreeListVO> articleTree = articleService.getTreeList();
        return Result.success(articleTree);
    }

}
